/**
 * 
 */

package automaton;

import interfaces.State;
import interfaces.Transition;

/**
 * @author LE VAN LINH
 *
 */
@SuppressWarnings("hiding")
public class TransitionImpl<String> implements Transition<String> {

	State sourceState;
	State destinationState;
	String label;
	
	/**
	 * Get the Source state of transition
	 * @return
	 */
	@Override
	public State source() {
		return sourceState;
	}

	/**
	 * Get the destination state of transition
	 * @return
	 */
	@Override
	public State target() {
		return destinationState;
	}

	/**
	 * Get the label of transition
	 * @return
	 */
	@SuppressWarnings("unchecked")
	@Override
	public String label() {
		if(this.label != null)
			return label;
		return (String)"";
	}

	public void setTarget(State target){
		this.destinationState = target;
	}
	
	public void setSourceState(State sourceState) {
		this.sourceState = sourceState;
	}

	public void setLabel(String label) {
		this.label = label;
	}

	public void reversedTransition(){
		State temp = source();
		setSourceState(destinationState);
		setTarget(temp);
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public boolean equals(Object obj) {
		TransitionImpl<String> trans = (TransitionImpl<String>) obj;
		if(this.source().equals(trans.source())
				&& this.target().equals(trans.target())
				&& this.label().equals(trans.label()))
				return true;
		return false;
	}
	
	/**
	 * Constructor of Transition
	 * @param sourceState
	 * @param destinationState
	 * @param label
	 */
	public TransitionImpl(State sourceState, State destinationState,
			String label) {
		super();
		this.sourceState = sourceState;
		this.destinationState = destinationState;
		this.label = label;
	}
	
}
